package com.ruoyi.web.controller.class_management;

import com.ruoyi.class_management.domain.TbClassMoralEducation;
import com.ruoyi.class_management.service.ITbClassMoralEducationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 班级德育Controller
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/class_management/education")
public class TbClassMoralEducationController extends BaseController
{
    @Autowired
    private ITbClassMoralEducationService tbClassMoralEducationService;

    /**
     * 查询班级德育列表
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbClassMoralEducation tbClassMoralEducation)
    {
        startPage();
        List<TbClassMoralEducation> list = tbClassMoralEducationService.selectTbClassMoralEducationList(tbClassMoralEducation);
        return getDataTable(list);
    }

    /**
     * 导出班级德育列表
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:export')")
    @Log(title = "班级德育", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbClassMoralEducation tbClassMoralEducation)
    {
        List<TbClassMoralEducation> list = tbClassMoralEducationService.selectTbClassMoralEducationList(tbClassMoralEducation);
        ExcelUtil<TbClassMoralEducation> util = new ExcelUtil<TbClassMoralEducation>(TbClassMoralEducation.class);
        util.exportExcel(response, list, "班级德育数据");
    }

    /**
     * 获取班级德育详细信息
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbClassMoralEducationService.selectTbClassMoralEducationById(id));
    }

    /**
     * 新增班级德育
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:add')")
    @Log(title = "班级德育", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbClassMoralEducation tbClassMoralEducation)
    {
        return toAjax(tbClassMoralEducationService.insertTbClassMoralEducation(tbClassMoralEducation));
    }

    /**
     * 修改班级德育
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:edit')")
    @Log(title = "班级德育", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbClassMoralEducation tbClassMoralEducation)
    {
        return toAjax(tbClassMoralEducationService.updateTbClassMoralEducation(tbClassMoralEducation));
    }

    /**
     * 删除班级德育
     */
    @PreAuthorize("@ss.hasPermi('class_management:education:remove')")
    @Log(title = "班级德育", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbClassMoralEducationService.deleteTbClassMoralEducationByIds(ids));
    }
}
